import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/common/no_permissions_widget.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/components/custom_progress.dart';
import 'package:safetymonitor/app/components/custom_refresh.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/values/colors.dart';
import 'package:safetymonitor/app/data/entities/application/get_statistice_score_entity.dart';

import 'controller.dart';

///指数评分
class IndexRatingPage extends StatelessWidget {
  IndexRatingPage({super.key});

  final controller = Get.put(IndexRatingController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          if (!controller.isNotPermissions) {
            return const NoPermissionsWidget();
          }
          return Scaffold(
            backgroundColor: AppColors.bg_page_color,
            appBar: CustomAppBar(
              titleText: '综合评分',
            ),
            body: Container(
              color: AppColors.bg_color_grey,
              padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
              child: Column(
                children: [
                  Expanded(
                      child: CustomEasyRefreshList<GetStatisticeScoreEntity>(
                    enableLoad: false,
                    dataLoad: controller.getStatisticsScore,
                    itemBuilder: (item, index) {
                      return _itemWidget(item);
                    },
                  ))
                ],
              ),
            ),
          );
        });
  }

  /// 标题
  Widget _title(String title, String? value) {
    return Row(
      children: [
        Text(
          title,
          style: TextStyle(
            color: const Color(0xffA5A6B5),
            fontSize: 13.sp,
            fontWeight: FontWeight.w400,
          ),
        ),
        if (value != null)
          Expanded(
              child: Text(
            value,
            style: TextStyle(
              color: const Color(0xff495061),
              fontSize: 13.sp,
              fontWeight: FontWeight.w400,
            ),
          )),
      ],
    );
  }

  Widget _itemWidget(GetStatisticeScoreEntity item) {
    return CustomTitleChartPage(
        title: item.companyName,
        child: Column(
          children: [
            // Row(
            //   children: [
            //     Expanded(child: _title('综合得分:', '${item.overallScore}')),
            //   ],
            // ),
            //0~1比例
            CustomProgressBar(
              // percentage: 0.45,
              percentage: item.overallScore<=0?0:item.overallScore/100,
              percentageS: item.overallScore,
            ),
          ],
        ));
  }
}
